package org.code.mallspringboot.controller;

import org.code.mallspringboot.pojo.SmsCouponHistory;
import org.code.mallspringboot.service.SmsCouponHistoryService;
import org.code.mallspringboot.vo.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/couponHistory")
public class SmsCouponHistoryController {

    @Autowired
    private SmsCouponHistoryService smsCouponHistoryService;

    @GetMapping("/list")
    public CommonResult list(@RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
                             @RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize,
                             Integer useStatus,
                             String orderSn,
                             Integer couponId){

        List<SmsCouponHistory> list = smsCouponHistoryService.selectPage(pageNum, pageSize, useStatus, orderSn, couponId);
        int total = smsCouponHistoryService.total(useStatus, orderSn, couponId);
        Map<String,Object> map = new HashMap<String, Object>();
        map.put("list" , list);
        map.put("total" , total);
        if (!map.isEmpty()){
            return CommonResult.success(map);
        }
        return CommonResult.failed("查询失败");
    }
}
